unit uWorkmanConsuption;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, ComCtrls, ToolWin, Grids, DBGridEh, StdCtrls;

type
  TfWorkmanConsuption = class(TForm)
    GroupBox1: TGroupBox;
    DBGridEh1: TDBGridEh;
    GroupBox2: TGroupBox;
    DBGridEh2: TDBGridEh;
    GroupBox3: TGroupBox;
    DBGridEh3: TDBGridEh;
    tbWorkmanConsuption: TToolBar;
    tbAddWorkmanConsuption: TToolButton;
    tbDelWorkmanConsuption: TToolButton;
    ToolBar2: TToolBar;
    MainMenu1: TMainMenu;
    N8: TMenuItem;
    MenuItem1: TMenuItem;
    N26: TMenuItem;
    N9: TMenuItem;
    N10: TMenuItem;
    N11: TMenuItem;
    N12: TMenuItem;
    procedure DBGridEh3KeyPress(Sender: TObject; var Key: Char);
    procedure N1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure tbAddWorkmanConsuptionClick(Sender: TObject);
    procedure tbDelWorkmanConsuptionClick(Sender: TObject);
    procedure N26Click(Sender: TObject);
  private
    procedure ApplyFilter();
    procedure FilterPeriod();
  public
    { Public declarations }
  end;

var
  fWorkmanConsuption: TfWorkmanConsuption;

implementation

uses uDBData, uFilterPeriod, uChangeReport;

{$R *.dfm}

procedure TfWorkmanConsuption.ApplyFilter();
begin
  fDBData.qWorkmanSalary.Active := False;
  fDBData.qWorkmanSalary.ParamByName('BeginDate').Value := fFilterPeriod.DateTimePicker1.Date;
  fDBData.qWorkmanSalary.ParamByName('EndDate').Value := fFilterPeriod.DateTimePicker2.Date;
  fDBData.qWorkmanSalary.Active := True;
end;

procedure TfWorkmanConsuption.FilterPeriod();
begin
  fFilterPeriod.ShowModal();
  while(True)do
  begin
    Application.ProcessMessages();
    if((fFilterPeriod.IsDataSet = True)or(fFilterPeriod.IsFormClosed = True)) then
    begin
      break;
    end;
  end;
  if(fFilterPeriod.IsDataSet)then
  begin
    ApplyFilter();
  end;
end;

procedure TfWorkmanConsuption.DBGridEh3KeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key = #13 then (Sender as TDBGridEh).DataSource.DataSet.Post;
end;

procedure TfWorkmanConsuption.N1Click(Sender: TObject);
begin
  FilterPeriod();
end;

procedure TfWorkmanConsuption.FormCreate(Sender: TObject);
begin
  ApplyFilter();
end;

procedure TfWorkmanConsuption.tbAddWorkmanConsuptionClick(Sender: TObject);
begin
  fDBData.InsertRecord(fDBData.dWorkmanConsuption);
end;

procedure TfWorkmanConsuption.tbDelWorkmanConsuptionClick(Sender: TObject);
begin
  fDBData.DeleteRecord(fDBData.dWorkmanConsuption);
end;

procedure TfWorkmanConsuption.N26Click(Sender: TObject);
begin
  fChangeReport.ShowModal();
end;

end.
